package cn.com.ghy.android.exception;

import java.net.SocketException;

import android.content.Context;
import android.os.Looper;
import android.widget.Toast;

public class DisposeException {

	private static DisposeException disposeException = null;

	private Context mContext = null;

	private DisposeException() {

	}

	public static DisposeException getInstance() {
		if (null == disposeException) {
			disposeException = new DisposeException();
		}
		return disposeException;
	}

	public void init(Context mContext) {
		this.mContext = mContext;
	}

	public void handleException(Throwable ex) {
		if (null == ex) {
			return;
		}
		String str = ex.getMessage();
		if (ex instanceof ArithmeticException) {
			str = "被除数为零!";
		} else if (ex instanceof NullPointerException) {
			str = "提交数据时出现空值,请联系管理员处理!";
		} else if (ex instanceof HttpRequestErrorException) {
			str = "请求URL异常,请联系管理员!";
		} else if (ex instanceof HttpResponseNullException) {
			str = "请求返回结果为空值,请联系管理员确认异常信息!";
		} else if (ex instanceof HttpSserverErrorException) {
			str = "服务器内部异常,请联系管理员处理!";
		} else if (ex instanceof java.net.SocketTimeoutException) {
			str = "连接超时,请重新连接!";
		} else if (ex instanceof ProgramParseException) {
			str = "程序解析异常,请联系管理员!";
		} else if (ex instanceof XMLCreateException) {
			str = "XML文件生成失败,请联系管理员处理!";
		} else if (ex instanceof SocketException) {
			str = "网络连接超时,请尝试重新连接!";
		}
		final String msg = str;
		new Thread() {
			@Override
			public void run() {
				Looper.prepare();
				Toast.makeText(mContext, "信息提示:" + msg, Toast.LENGTH_LONG).show();
				Looper.loop();
			}
		}.start();
	}

}
